<template>
  <div class="top-banner">
    <!--  左侧列表-->
    <div class="top-banner-left" @mouseleave="mouseLeaveEvent">
      <!--      商品分类列表-->
      <ul class="back-color">
        <li @mouseenter="getSideItemsType(item.type)" class="left-tag"
            v-for="item in allInfo.sideItems">{{
            item.content
          }}
        </li>
      </ul>
      <!--      鼠标经过显示商品信息-->
      <transition name="animate__animated animate__bounce" :appear="true" enter-active-class="animate__fadeIn"
                  leave-active-class="animate__fadeOut">
        <div v-show="whetherShowLeftTagMessage" class="left-tag-message">
          <ul class="category-items">
            <li v-for="item in getLeftTagMessageTag" class="left-tag-message-tag">
              
              <a class="goods-link" :href="item.sourceUrl">
                <img :src="item.imgUrl" alt=""/>
                <div class="text-name">
                  {{ item.name }}
                </div>
              </a>
              <a class="goods-buy-link"
                 v-show="item.buyStatus"
                 :href="item.buyUrl">
                选购
              </a>
            </li>
          </ul>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  name: "TopBanner",
  data() {
    return {
      allInfo: {},
      MouseenterGetSideItemType: null,
      whetherShowLeftTagMessage: false,
    }
  },
  computed: {
    getLeftTagMessageTag() {
      return this.allInfo[this.MouseenterGetSideItemType]
    }
  },
  created() {
    this.getAllInfo()
  },
  methods: {
    async getAllInfo() {
      const {data: res} = await this.$http.get('topbanner')
      this.allInfo = res
    },
    getSideItemsType(type) {
      this.MouseenterGetSideItemType = type
      this.whetherShowLeftTagMessage = true
    },
    mouseLeaveEvent() {
      this.whetherShowLeftTagMessage = false
    },
  },
}
</script>

<style scoped lang="less">
.top-banner {
  position: absolute;
  display: inline-block;
  margin-top: 10px;
  z-index: 99999;
  .top-banner-left {
    width: 230px;
    position: relative;
    
    .back-color {
      display: flex;
      flex-wrap: wrap;
      padding: 20px 0;
      background: rgba(0, 0, 0, 0.3);
      
      .left-tag {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 230px;
        height: 42px;
        color: #ffffff;
        font-size: 14px;
      }
      
      .left-tag:hover {
        background-color: #ED702F;
      }
    }
    
    .left-tag-message {
      height: 460px;
      position: absolute;
      left: 230px;
      top: 0;
      z-index: 1000;
      
      .category-items {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        writing-mode: vertical-lr; //flex-wrap: wrap 溢出换行但是父盒子没有被撑开的解决办法
        height: 460px;
        background: #fff;
        border: 1px solid #e0e0e0;
        box-shadow: 3px 8px 16px rgba(0, 0, 0, 0.18);
        
        .left-tag-message-tag {
          
          writing-mode: horizontal-tb; //flex-wrap: wrap 溢出换行但是父盒子没有被撑开的解决办法
          display: flex;
          flex-flow: row nowrap;
          justify-content: space-between;
          align-items: center;
          width: 265px;
          height: 76.6px;
          padding: 0 20px 0 20px;
          box-sizing: border-box;
          background: #fff;
          cursor: pointer;
          
          .goods-link {
            display: flex;
            flex-flow: row nowrap;
            justify-content: flex-start;
            align-items: center;
            width: 170px;
          }
          
          .text-name {
            padding-left: 10px;
            font-size: 14px;
          }
          
          .goods-buy-link {
            display: block;
            width: 58px;
            height: 22px;
            line-height: 24px;
            font-size: 12px;
            text-align: center;
            color: #ff6700;
            border: 1px solid #ff6700;
            
            &:hover {
              color: #fff;
              background: #ff6700;
            }
          }
        }
      }
    }
  }
}
</style>
